
import { ResponseBody, ResponseCode } from "./ResponseHelper"

export default class ResultHelper {
  /**
   * 返回成功的消息体
   * @param data 返回数据
   * @param msg 消息
   * @returns code default 2000
   */
  static success(data: object | unknown[] = {}, msg: string = ""): ResponseBody {
    return {
      code: ResponseCode.PASS,
      msg,
      data
    }
  }

  /**
   * 发送一个错误的消息体
   * @param msg 
   * @param code 
   * @param data 
   * @returns code default 4000
   */
  static error(msg: string | string[] = "", code: number = ResponseCode.ERROR, data: object | unknown[] = {}): ResponseBody {
    return {
      msg,
      code,
      data
    }
  }

  /**
   * 发送一个没有权限的消息体
   * @param msg 
   * @param code 
   * @param data 
   * @returns code default 4003
   */
  static reject(msg: string | string[] = "", code: number = ResponseCode.NOT_ALLOW, data: object | unknown[] = {}): ResponseBody {
    return {
      msg,
      code,
      data
    }
  }

}
